package presstrack
{
	import org.presstrack.service.CrudService;
	import org.presstrack.vos.TrackStateVO;
	
	[RemoteClass(alias="presstrack.OperationClass")]
	
	[Bindable]
	public class OperationClass
	{
		public var iOperationId:int;
		public var mLabel:String;
		public var iSection:int;
		public var iIsChecked:int;
		public var arFactors:Array;
				
		public function OperationClass(operation:Object = null)
		{
			iIsChecked	= 0;
			arFactors	= new Array();
			if (operation != null)
			{
				setFrom(operation);
			}			 
		}	
		
		public function setFrom(ob:Object):void
		{
			if (ob.hasOwnProperty("iOperationId"))
			{
				iOperationId = Number(ob.iOperationId);
			}
			
			if (ob.hasOwnProperty("mLabel"))
			{
				mLabel = ob.mLabel;
			}
			
			if (ob.hasOwnProperty("iSection"))
			{
				iSection = ob.iSection;
			}
			
			if (ob.hasOwnProperty("iIsChecked"))
			{
				iIsChecked = ob.iIsChecked;
			}
			
			if (ob.hasOwnProperty("arFactors"))
			{
				arFactors = ob.arFactors;
			}				
		}
		
		public function toTask():TaskClass
		{
			var task:TaskClass	= new TaskClass;		
			task.label 			= mLabel;
			task.section		= iSection;
			task.state			= new TrackStateVO("1");
			task.order			= CrudService.curOrder.iOrderId;
			task.execute		= CrudService.company;
			task.cost			= "0.00";
						
			for each (var f:Object in arFactors) 
			{
				task.value += f.label + " : " + f.selected;
				task.value += '\r';
			}
			return task;
		}
	}
}